﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Workflow.Flow;
using Jzy.Core.Common;
using System.Data;
using Frame.Lib.Web;
using Frame.Lib.Utilities;

namespace Jzy.Web.WorkFlow.Design
{
    public partial class List : PageList
    {
        private FlowBO _flow = new FlowBO();
        private PagerSortSetting _setting;
        protected void Page_Load(object sender, EventArgs e)
        {
            _setting = this.Footer1.InitPager(new BindViewHandler(BindView));
            if (!IsPostBack)
            {
                BindView();
            }
            InitSelectID(hidSelectIDs);
            AddAttr();
            JSUtil.SetTableHeight("list", 140);
        }

        private void AddAttr()
        {
            JSUtil.DelConfirm(btnDelete, "流程");
            JSUtil.ClickBtn(lnkDelete, btnDelete);
            lnkAdd.HRef = "Tab1.aspx";
        }

        private void BindView()
        {
            lv.DataKeyNames = new string[] { "ID" };
            InitLV(lv, lvHeader);
            List<FlowInfo> list = _flow.GetList();
            lv.DataSource = _setting.GetList<FlowInfo>(list);
            lv.DataBind();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (strSelectIDs != "")
            {
                _flow.Delete(strSelectIDs, true);
                BindView();
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            BindView();
        }

        protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                string id = lv.DataKeys[((ListViewDataItem)e.Item).DataItemIndex]["ID"].ToString();
                HyperLink lnkEdit = (HyperLink)e.Item.FindControl("lnkEdit");
                lnkEdit.NavigateUrl = "Tab1.aspx?FlowID=" + id;
            }
        }
    }
}
